package cn.fourhundredandeighteen.view.TeacherView.SetStudentCourseScore;

import cn.fourhundredandeighteen.view.Component.Button;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class MyButtonRender implements TableCellRenderer {
    private JPanel panel;

    private JButton button;
    private JButton button1;

    public MyButtonRender() {
        this.initButton();

        this.initPanel();
        this.initButton2();
        // 添加按钮。
        // this.panel.add(this.button);
        this.panel.add(this.button1);


    }

    private void initButton() {
        this.button = new Button();
        this.button.setText("\u8bbe\u7f6e\u6210\u7ee9");
        // 设置按钮的大小及位置。
        this.button.setBounds(8, 3, 100, 25);
    }

    private void initButton2() {
        this.button1 = new Button();
        this.button1.setText("\u8bbe\u7f6e\u6210\u7ee9");
        // 设置按钮的大小及位置。
        this.button1.setBounds(8, 3, 100, 25);
    }

    private void initPanel() {
        this.panel = new JPanel();

        // panel使用绝对定位，这样button就不会充满整个单元格。
        this.panel.setLayout(null);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
                                                   int column) {
        // 只为按钮赋值即可。也可以作其它操作，如绘背景等。
        this.button.setText(value == null ? "" : String.valueOf(value));

        return this.panel;
    }

}